﻿using SimpleConnection_UDP_WIN.extension_class.form_ui;
using SimpleConnection_UDP_WIN.extension_class.utils;
using SimpleConnection_UDP_WIN.interface_class;
using SimpleConnection_UDP_WIN.utils.UDP;
using System.Windows.Forms;

namespace SimpleConnection_UDP_WIN.extension_class.form_ui
{
    internal class NetworkMediaPlayClass : PluginAbstractClass, PluginBaseInfoInterface
    {


        //传入命令的关键协议名，如 协议名为 a ， 那么这个类只能接受  a://这种协议
        public const string Protocol = "net_media";

        //必须保留空构造
        public NetworkMediaPlayClass()
        {
        }
        //必须拥有传入 消息的构造
        public NetworkMediaPlayClass(string message, string ip, int port) : base(message, ip, port)
        {
            this.message = message;
            this.ip = ip;
            this.port = port;

        }

        //插件的 各种信息
        public string Name => "网络媒体播放";
        public string Describe => "此类可以在线播放网络媒体，包括音频、视频、图片";
        public string Version => "1.0.0";
        public string Help => "-";

        public const string KEY_IMAGE = "image";
       public const string KEY_AUDIO = "audio";
       public const string KEY_VIDEO = "video";

        /// <summary>
        /// 主要执行方法，在此处 可以调用 MessageParsingClass 的方法来帮助解析 message
        /// </summary>
        public void exec()
        {
            //判断是否验证了密码
            if (MessageParsingClass.isAdmin(message))
            {
                string url = MessageParsingClass.getString(message);
                switch (MessageParsingClass.getKey(message))
                {
                    case KEY_IMAGE:
                        new NetMediaForm(url,KEY_IMAGE).Show();
                        break;
                    case KEY_VIDEO:
                        new NetMediaForm(url, KEY_VIDEO).Show();
                        break;
                    case KEY_AUDIO:
                        new NetMediaForm(url, KEY_AUDIO).Show();
                        break;
                    default:
                        break;
                }

                //返回给 它 的信息，默认发送到 8871
               // new UdpTool(ip, 8871).SendMessage(GetType().Name, $"向它发送反馈");
            }
        }

    }
}
